﻿<Window xmlns:my1="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"  x:Class="RESTester.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:ad="clr-namespace:AvalonDock;assembly=AvalonDock"
        xmlns:sysWin="clr-namespace:System.Windows;assembly=PresentationFramework"
        xmlns:my="clr-namespace:RESTester"
        xmlns:local="clr-namespace:RESTester"
        xmlns:winForms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
        Title="RESTester" MinWidth="850" MinHeight="300">

    <Window.Resources>
        <ContextMenu x:Key="SharedInstanceContextMenu">
            <MenuItem Header="Load" Click="loadMenuItem_Click"/>
            <MenuItem Header="Remove" Click="removeMenuItem_Click"/>
        </ContextMenu>

        <Style x:Key="MyItemContainerStyle" TargetType="{x:Type ListBoxItem}">
            <Setter Property="ContextMenu" Value="{StaticResource SharedInstanceContextMenu}" />
        </Style>
    </Window.Resources>

    <Grid x:Name="mainGrid" Margin="5">
        <ad:DockingManager x:Name="dockManager">
            <ad:ResizingPanel Orientation="Vertical">
                <ad:ResizingPanel Orientation="Horizontal">

                    <ad:ResizingPanel ad:ResizingPanel.ResizeWidth="200">
                        <ad:DockablePane>
                            <ad:DockableContent x:Name="dbContainer" Title="DB">
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="50" />
                                        <RowDefinition Height="5" />
                                        <RowDefinition />
                                    </Grid.RowDefinitions>

                                    <Grid Grid.Column="0" Margin="1">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition />
                                            <ColumnDefinition Width="5" />
                                            <ColumnDefinition />
                                        </Grid.ColumnDefinitions>

                                        <Grid.RowDefinitions>
                                            <RowDefinition />
                                            <RowDefinition Height="2" />
                                            <RowDefinition />
                                        </Grid.RowDefinitions>

                                        <Grid Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="0">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition />
                                                <ColumnDefinition Width="5" />
                                                <ColumnDefinition />
                                            </Grid.ColumnDefinitions>

                                            <TextBox x:Name="requestNameTextBox" Grid.Column="0" KeyDown="requestNameTextBox_KeyDown" />

                                            <Button x:Name="saveRequest" Grid.Column="2" Content="Save" Click="saveRequest_Click"/>

                                        </Grid>

                                        <Button x:Name="loadRequests" Grid.Column="0" Grid.ColumnSpan="3" Grid.Row="2" Content="Refresh" Click="loadRequests_Click"/>

                                    </Grid>

                                    <ListView Name="requestsView" Grid.Row="2" ItemsSource="{Binding Requests}" ItemContainerStyle="{StaticResource MyItemContainerStyle}">
                                        <ListView.View>
                                            <GridView>
                                                <GridViewColumn Width="140" Header="Name" DisplayMemberBinding="{Binding Name}" />
                                                <GridViewColumn Width="70" Header="Method" DisplayMemberBinding="{Binding Method}" />
                                                <GridViewColumn Width="140" Header="Url"  DisplayMemberBinding="{Binding Url}" />                                                
                                            </GridView>
                                        </ListView.View>
                                    </ListView>
                                    
                                </Grid>
                            </ad:DockableContent>
                        </ad:DockablePane>
                    </ad:ResizingPanel>

                    <ad:ResizingPanel Orientation="Vertical">

                        <ad:ResizingPanel ad:ResizingPanel.ResizeHeight="50">
                            <ad:DockablePane>
                                <ad:DockableContent x:Name="actionContainer" Title="Action">
                                    <Grid Margin="1">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="1*" />
                                            <ColumnDefinition Width="30"/>
                                            <ColumnDefinition Width="5*" />
                                            <ColumnDefinition Width="2"/>
                                            <ColumnDefinition Width="5*"/>
                                            <ColumnDefinition Width="2"/>
                                            <ColumnDefinition Width="7*"/>
                                            <ColumnDefinition Width="2"/>
                                            <ColumnDefinition Width="7*"/>
                                        </Grid.ColumnDefinitions>

                                        <Button x:Name="clearAll" Grid.Column="0" Content="Clear" Click="clearAll_Click" Background="Gray" Foreground="White" FontStyle="Italic" FontWeight="Bold"/>
                                        <Button x:Name="getBtn" Grid.Column="2" Content="Do request" Click="getBtn_Click" HorizontalAlignment="Stretch" Background="LightGray" Foreground="Green" FontWeight="Bold"/>
                                        <ComboBox Name="methodBox" Grid.Column="4" SelectedIndex="0" ItemsSource="{my:EnumValues my:HTTPMethod}"/>


                                        <Grid Grid.Column="6">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="30" />
                                                <ColumnDefinition />
                                            </Grid.ColumnDefinitions>

                                            <Label Grid.Column="0" Content="Url:" Target="{Binding ElementName=requestUrl}" />
                                            <TextBox x:Name="requestUrl" Grid.Column="1" VerticalContentAlignment="Center" />
                                        </Grid>

                                        <Grid Grid.Column="8">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="85" />
                                                <ColumnDefinition />
                                            </Grid.ColumnDefinitions>

                                            <Label Grid.Column="0" Content="Content Type:" Target="{Binding ElementName=requestUrl}" />
                                            <ComboBox Grid.Column="1" x:Name="contentTypeBox" ItemsSource="{Binding ContentTypes, Mode=OneTime}" IsEditable="True" IsTextSearchEnabled="True"/>
                                        </Grid>

                                    </Grid>
                                </ad:DockableContent>
                            </ad:DockablePane>
                        </ad:ResizingPanel>

                        <ad:ResizingPanel Orientation="Horizontal">

                            <ad:ResizingPanel Orientation="Vertical">
                                <ad:DockablePane ad:ResizingPanel.ResizeHeight="100">
                                    <ad:DockableContent x:Name="requestContentContainer" Title="Request Body">
                                        <TextBox x:Name="requestContentTextBox" AcceptsReturn="True" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto"/>
                                    </ad:DockableContent>
                                </ad:DockablePane>

                                <ad:DockablePane>
                                    <ad:DockableContent x:Name="requestHeadersContainer" Title="Request Headers">
                                        <TabControl x:Name="responseTabControl">

                                            <TabItem Header="Plain text" Width="80" Margin="0 0 0 1">
                                                <TextBox x:Name="responseTextBox" AcceptsReturn="True" IsReadOnly="True" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto"/>
                                            </TabItem>

                                            <TabItem Header="XML" Width="80" Margin="0 0 0 1">
                                                <TextBox x:Name="responseXmlTextBox" AcceptsReturn="True" IsReadOnly="True" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto"/>
                                            </TabItem>

                                            <TabItem Header="JSON" Width="80" Margin="0 0 0 1">
                                                <TextBox x:Name="responseJsonTextBox" AcceptsReturn="True" IsReadOnly="True" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto"/>
                                            </TabItem>

                                            <TabItem Header="WEB" Width="80" Margin="0 0 0 1">
                                                <WebBrowser x:Name="responseWebBrowser" />
                                            </TabItem>

                                        </TabControl>
                                    </ad:DockableContent>
                                </ad:DockablePane>
                            </ad:ResizingPanel>

                            <ad:ResizingPanel Orientation="Vertical">
                                <ad:DockablePane ad:ResizingPanel.ResizeHeight="200">
                                    <ad:DockableContent x:Name="responseContainer" Title="Response">
                                        <DataGrid x:Name="requestHeadersGrid" CanUserAddRows="True" CanUserDeleteRows="True" CanUserSortColumns="True" AutoGenerateColumns="false" CanUserReorderColumns="False" ItemsSource="{Binding RequestHeaders, Mode=TwoWay}" >
                                            <DataGrid.Columns>
                                                <DataGridTextColumn Header="Name" Binding="{Binding Name}" Width="200"/>
                                                <DataGridTextColumn Header="Value" Binding="{Binding Value}" Width="200" />
                                            </DataGrid.Columns>
                                        </DataGrid>
                                    </ad:DockableContent>
                                </ad:DockablePane>
                                <ad:DockablePane>
                                    <ad:DockableContent x:Name="responseHeadersContainer" Title="Response Headers">
                                        <DataGrid x:Name="responseHeadersGrid" CanUserSortColumns="True" AutoGenerateColumns="false" CanUserReorderColumns="False" ItemsSource="{Binding ResponseHeaders, Mode=TwoWay}" IsReadOnly="True">
                                            <DataGrid.Columns>
                                                <DataGridTextColumn Header="Name" Binding="{Binding Name}" Width="200"/>
                                                <DataGridTextColumn Header="Value" Binding="{Binding Value}" Width="200" />
                                            </DataGrid.Columns>
                                        </DataGrid>
                                    </ad:DockableContent>
                                </ad:DockablePane>
                            </ad:ResizingPanel>

                        </ad:ResizingPanel>

                    </ad:ResizingPanel>
                </ad:ResizingPanel>

                <ad:DockablePane ad:ResizingPanel.ResizeHeight="185">
                    <ad:DockableContent x:Name="logContainer" Title="Log">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="10*"/>
                                <ColumnDefinition Width="5" />
                                <ColumnDefinition Width="1*"/>
                            </Grid.ColumnDefinitions>


                            <TextBox x:Name="logTextBox" Grid.Column="0" AcceptsReturn="True" IsReadOnly="True" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto"/>

                            <Button x:Name="donateBtn" Grid.Column="2" Click="donateBtn_Click" ToolTip="Copyright (C) 2012-2013 Jorgen Bumajnikov. All rights reserved.">
                                <Button.Content>
                                    <Image x:Name="donateImage" Source="/RESTester;component/donate_chepushila_coin_button_.png" />
                                </Button.Content>
                            </Button>
                        </Grid>
                    </ad:DockableContent>
                </ad:DockablePane>
            </ad:ResizingPanel>
        </ad:DockingManager>

        <Grid Background="Transparent" x:Name="loaderBlock" Visibility="Hidden" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
            <my1:WindowsFormsHost VerticalAlignment="Center" HorizontalAlignment="Center">
                <winForms:PictureBox x:Name="loader" />
            </my1:WindowsFormsHost>
        </Grid>
    </Grid>
</Window>
